package com.stark.commons.spring.web.support.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.ServletRequestBindingException;

/**
 * {@link ServletRequestBindingException} 异常处理器。
 * <p>返回 <code>400</code>状态码及错误信息。
 * @author Ben
 * @since 1.0.0
 * @version 1.0.0
 */
public class ServletRequestBindingExceptionHandler implements ExceptionHandler {

	@Override
	public boolean instanceofException(Exception ex) {
		return ex instanceof ServletRequestBindingException;
	}

	@Override
	public ResponseEntity<String> handle(Exception ex) {
		return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(((ServletRequestBindingException) ex).getMessage());
	}

}
